<?php

use yii\db\Migration;

class m000000_000011_create_user extends Migration
{
    public function up()
    {
        $this->createTable('{{%user}}', [
            'id'=>$this->primaryKey(), // PK
            'mobile'=>$this->string(32), // 手机号码
            'nickname'=>$this->string(256), // 昵称
            'password'=>$this->string(256), // HASH密码
            'auth_key' =>$this->string(32),
            'email'=>$this->string(256), // 电子邮箱
            'avatar'=>$this->string(256), // 头像
            'type'=>$this->integer(), // 用户类型
            'status'=>$this->integer(), // 状态
            'create_time'=>$this->integer(), // 创建时间
            'last_login_type'=>$this->integer(), // 上次登录类型
        ]);
        $this->batchInsert('{{%key_map}}', ['t', 'k', 'v'], [
            ['user_type', 1, '普通用户'],
            ['user_type', 2, 'VIP用户'],
        ]);
        $this->batchInsert('{{%key_map}}', ['t', 'k', 'v'], [
            ['user_status', 1, '正常'],
            ['user_status', 9, '停止'],
            ['user_status', 0, '删除'],
        ]);
    }

    public function down()
    {
        $this->delete('{{%key_map}}', ['t'=>'user_type']);
        $this->delete('{{%key_map}}', ['t'=>'user_status']);
        $this->dropTable('{{%user}}');
    }
}
